package com.ytu.clouddisk.utils;

import com.ytu.clouddisk.face.R;

import android.content.Context;

public class CommonUtil {

	public static String checkType(Context mContext, String fileName) {
		// 判断文件后缀名，使用相应图片
		if (CommonUtil.checkEndsWithInStringArray(fileName, mContext
				.getResources().getStringArray(R.array.fileEndingImage))) {
			return "image/*";
		} else if (CommonUtil.checkEndsWithInStringArray(fileName, mContext
				.getResources().getStringArray(R.array.fileEndingAudio))) {
			return "audio/*";
		} else if (CommonUtil.checkEndsWithInStringArray(fileName, mContext
				.getResources().getStringArray(R.array.fileEndingVideo))) {
			return "*/*";
		} else if (CommonUtil.checkEndsWithInStringArray(fileName, mContext
				.getResources().getStringArray(R.array.fileEndingPackage))) {
			return "*/*";
		} else if (CommonUtil.checkEndsWithInStringArray(fileName, mContext
				.getResources().getStringArray(R.array.fileEndingText))) {
			return "text/*";
		} else {
			return "*/*";
		}
	}

	/**
	 * 判断文件类型
	 * 
	 * @param checkItsEnd
	 * @param fileEndings
	 * @return
	 */
	public static boolean checkEndsWithInStringArray(String checkItsEnd,
			String[] fileEndings) {
		for (String aEnd : fileEndings) {
			if (checkItsEnd.endsWith(aEnd))
				return true;
		}
		return false;
	}

}
